package com.group9.handinhand.dao.model;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.apache.commons.lang.ArrayUtils;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import com.group9.handinhand.service.so.OfferPostSO;

@Entity
@Table(name = "OFFER_POST")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class OfferPost extends Post {
	
	private static final long serialVersionUID = 1L;
	
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "OFFER_ID", nullable = false)
	private Offer offer;
	
	public OfferPostSO convertToServiceObject(String... ignoreProperties) {
		OfferPostSO so = (OfferPostSO) convert(new OfferPostSO(), 
			(String[]) ArrayUtils.addAll(ignoreProperties, new String[]{"offer","user"}));
		so.setUser(super.getUser().convertToServiceObject(new String[]{"socialUsers"}));
		so.setOffer(offer.convertToServiceObject(new String[]{"moderators", "posts"}));
		return so;
	}
	
	public Offer getOffer() {
		return offer;
	}

	public void setOffer(Offer offer) {
		this.offer = offer;
	}

	@Override
	public String toString() {
		return "OfferPost [offer=" + offer + "]";
	}
	
	

}
